package com.wavehi.config;

import com.wavehi.pojo.Person;
import com.wavehi.pojo.Pet;
import com.wavehi.pojo.User;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

/**
 * @Author WaveHi
 * @Date 31/10/2021 下午 10:06
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description
 */
@ImportResource("classpath:beans-02.xml")
@Configuration
public class MyConfigure {

    @Bean
    public Pet getPet() {
        return new Pet("Cat", 4);
    }

    @ConditionalOnBean(Pet.class)
    @Bean
    public User getUser() {
        return new User("Marry", "qwerty");
    }

    @ConditionalOnBean(name="getPet")
    @Bean
    public Person getPerson() {
        return new Person("Tom", getPet());
    }
}
